package view;
import business.Aluno;
import business.Funcionario;
import business.Pesquisar;
import business.Professor;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import javax.swing.text.MaskFormatter;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PesquisarP extends javax.swing.JFrame {
	private String titulo_;
	private JButton jButtonCancelar;
	private JButton jButtonOk;
	private JFormattedTextField jTextFieldCpf;
	private JLabel jLabel1;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				PesquisarP inst = new PesquisarP();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public PesquisarP() {
		super();
		initGUI();
	}
	
	public PesquisarP(String titulo_) {
		super();
		this.titulo_=titulo_;
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			setTitle(titulo_);
			AnchorLayout thisLayout = new AnchorLayout();
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jButtonCancelar = new JButton();
				getContentPane().add(jButtonCancelar, new AnchorConstraint(702, 614, 910, 218, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jButtonCancelar.setText("CANCELAR");
				jButtonCancelar.setPreferredSize(new java.awt.Dimension(121, 36));
				jButtonCancelar.setFont(new java.awt.Font("Segoe UI",0,16));
			}
			{
				jButtonOk = new JButton();
				getContentPane().add(jButtonOk, new AnchorConstraint(702, 854, 910, 631, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jButtonOk.setText("OK");
				jButtonOk.setPreferredSize(new java.awt.Dimension(68, 36));
				jButtonOk.setFont(new java.awt.Font("Segoe UI",0,16));
				jButtonOk.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Pesquisar objetoPesquisar = new Pesquisar();
						if (titulo_.equals("Pesquisar Aluno")){
							Aluno aluno = objetoPesquisar.pesquisarAluno(jTextFieldCpf.getText());
							Editar objetoEditar = new Editar(aluno);
							objetoEditar.show();
							}
							else if(titulo_.equals("Pesquisar Professor")){
							Professor professor = objetoPesquisar.pesquisarProfessor(jTextFieldCpf.getText());
							Editar objetoEditar = new Editar(professor);
							objetoEditar.show();
							}
							else if(titulo_.equals("Pesquisar Funcionario")){
							Funcionario funcionario = objetoPesquisar.pesquisarFuncionario(jTextFieldCpf.getText());
							Editar objetoEditar = new Editar(funcionario);
							objetoEditar.show();
							}
						
					}
				});
			}
			{
				jTextFieldCpf = new JFormattedTextField(MascaraCPF("###.###.###-##"));
				getContentPane().add(jTextFieldCpf, new AnchorConstraint(267, 795, 408, 50, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jTextFieldCpf.setPreferredSize(new java.awt.Dimension(227, 26));
				jTextFieldCpf.setFont(new java.awt.Font("Segoe UI",0,16));
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1, new AnchorConstraint(78, 234, 235, 60, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jLabel1.setText("CPF");
				jLabel1.setPreferredSize(new java.awt.Dimension(53, 29));
				jLabel1.setFont(new java.awt.Font("Segoe UI",0,16));
			}
			pack();
			this.setSize(321, 211);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	public MaskFormatter MascaraCPF(String Mascara){  
        
	       MaskFormatter F_Mascara = new MaskFormatter();  
	       try{  
	           F_Mascara.setMask(Mascara); //Atribui a mascara  
	           F_Mascara.setPlaceholderCharacter(' '); //Caracter para preencimento   
	       }  
	       catch (Exception excecao) {  
	       excecao.printStackTrace();  
	       }   
	       return F_Mascara;  
	}  
}
